import redis


class RedisDb:
    def __init__(self):
        self.rdb = redis.Redis(host='127.0.0.1', port='6379', db=1)

    def init_data(self, items):
        print('清空redis数据库，准备重新装载..')
        self.rdb.flushdb()

        for item in items:
            self.set(item['article_url'], True)
        print('数据装载完成')

    def get(self, key):
        if self.rdb.get(key) is None:
            return False
        return True

    def set(self, key, value):
        self.rdb.set(key, value)

    def flush(self):
        self.rdb.flushdb()
